#include "AVLTree.h"
#include "RBTree.h"
#include <vector>
#include <chrono>
#include <ctime>

int main()
{
	const int N = 10000000;
	vector<int> v;
	v.reserve(N);
	srand(time(0));
	for (size_t i = 0; i < N; i++)
	{
		v.push_back(i);
	}

	// 1.avl树的性能
	AVLTree<int, int> avlt;
	auto start = std::chrono::high_resolution_clock::now();
	for (auto e : v)
	{
		avlt.Insert(make_pair(e, e));
	}
	auto end = std::chrono::high_resolution_clock::now();

	std::chrono::duration<double> elapsed_time = end - start;
	std::cout << "Elapsed time: " << elapsed_time.count() << " seconds" << std::endl;

	cout << " AVLTree: isBalance:" << avlt.IsBalance() << endl;	   // 1
	cout << " AVLTree: height:" << avlt.Height() << endl;		   // 24

	// 2.红黑树的性能
	RBTree<int, int> rbt;
	auto start1 = std::chrono::high_resolution_clock::now();
	for (auto e : v)
	{
		rbt.Insert(make_pair(e, e));
	}
	auto end1 = std::chrono::high_resolution_clock::now();

	std::chrono::duration<double> elapsed_time2 = end1 - start1;
	std::cout << "Elapsed time: " << elapsed_time2.count() << " seconds" << std::endl;

	cout << " RBTree: isBalance:" << rbt.IsRBTree() << endl;	   // 1
	cout << " RBTree: height:" << rbt.Height() << endl;		   // 24
	cout << " RBTree: rotateCount:" << rbt._rotateCount << endl; // 1kw数据旋转900w次
	return 0;
}